package june.test_6_11;

import java.util.Scanner;

public class TestMain1 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String str1 = scanner.nextLine();
        String str2 = scanner.nextLine();
        int count = 0;

        for (int i = 0; i < str2.length();i++) {
            char c2 = str2.charAt(i);
            char c1 = str1.charAt(count);
            if(c2 == '^' && count == 0) {
                count++;
            } else if(c2 == '&' && count == str1.length() - 1) {
                if(i == str2.length() - 1 ) {
                    System.out.println(1);
                    return;
                } else {
                    for (int j = i + 1; j < str2.length(); j++) {
                        if(str2.charAt(j) != '*' && str2.charAt(j) != '?') {
                            System.out.println(0);
                            return;
                        }
                    }
                    System.out.println(1);
                    return;
                }
            } else if(c2 == '*') {

            }
        }
    }
}
